package com.tencent.wxcloudrun.common;

import com.tencent.wxcloudrun.model.AdminUser;
import lombok.extern.slf4j.Slf4j;

/**
 * ClassName: ThreadLocalUtils
 * Package: com.tencent.wxcloudrun.common
 * Description:
 *
 * @Date: 2023/1/23 4:35 PM
 * @Author: wht
 */


@Slf4j
public class ThreadLocalUtils {

//    // token
//    private static final ThreadLocal<String> CONTEXT_token = new ThreadLocal<>();
//
//    public static String getToken() {
//        return CONTEXT_token.get();
//    }
//
//    public static void setToken(String token) {
//        CONTEXT_token.set(token);
//    }

    //     userBean
    private static final ThreadLocal<AdminUser> CONTEXT_user = new ThreadLocal<>();

    public static AdminUser getUser() {
        return CONTEXT_user.get();
    }

    public static void setUser(AdminUser adminUser) {
        CONTEXT_user.set(adminUser);
    }

    // 当前时间
    private static final ThreadLocal<Long> CONTEXT_time = new ThreadLocal<>();

    public static Long getTime() {
        return CONTEXT_time.get();
    }

    public static void setTime() {
        CONTEXT_time.set(System.currentTimeMillis());
    }

    public static void remove() {
//        CONTEXT_token.remove();
        CONTEXT_user.remove();
        CONTEXT_time.remove();
    }
}

